package com.gz.logistics.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gz.logistics.R;
import com.gz.logistics.library.pojo.OrderInfo;
import com.gz.logistics.library.pojo.OrderInfoY;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * author 杜志娟
 * 已签收订单的适配器
 */
public class QueryOrderAdapterY extends BaseAdapter {
    private List<OrderInfoY> mDataList;
    private Context mContext;

    public QueryOrderAdapterY(List<OrderInfoY> mDataList, Context mContext) {
        this.mDataList = mDataList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int i) {
        return mDataList.get(i);
    }

    @Override
    public long getItemId(int i) {

        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null){
            view = LayoutInflater.from(mContext).inflate(R.layout.query_order_item,null);
            holder = new ViewHolder();
            holder.tv_order_number = (TextView) view.findViewById(R.id.tv_order_number);
            holder.tv_create_time = (TextView) view.findViewById(R.id.tv_create_time);
            holder.tv_receiver_name = (TextView) view.findViewById(R.id.tv_receiver_name);
            holder.tv_receiver_phone = (TextView) view.findViewById(R.id.tv_receiver_phone);
            holder.tv_receiver_address = (TextView) view.findViewById(R.id.tv_receiver_address);
            holder.tv_receiver_cpucbt = (TextView) view.findViewById(R.id.tv_receiver_cpucbt);
            holder.tv_pay_type = (TextView) view.findViewById(R.id.tv_pay_type);
            holder.tv_money = (TextView) view.findViewById(R.id.tv_money);
            holder.tv_receiver_outtime = (TextView) view.findViewById(R.id.tv_receiver_outtime);
            holder.tv_status = (TextView) view.findViewById(R.id.tv_status);
            holder.rl_paystatus = (RelativeLayout) view.findViewById(R.id.rl_paystatus);
            holder.rl_paystatus.setVisibility(View.GONE);
            view.setTag(holder);

        }else {
            holder = (ViewHolder) view.getTag();
        }

        final  OrderInfoY info  = mDataList.get(i);
        holder.tv_order_number.setText("订单编号："+info.getSn());
        holder.tv_receiver_name.setText("收货人姓名："+info.getReceiver_name());
        holder.tv_receiver_phone.setText("收货人电话："+info.getReceiver_tel());
        holder.tv_receiver_address.setText("收货人地址："+info.getReceiver_add());
        if (info.getReceive_type().equals("1")){
            holder.tv_receiver_cpucbt.setText("收款方式："+"现金支付");
        }else if(info.getReceive_type().equals("2")){
            holder.tv_receiver_cpucbt.setText("收款方式："+"POS机闪付");
        }else if(info.getReceive_type().equals("3")){
            holder.tv_receiver_cpucbt.setText("收款方式："+"在线支付");
        }
        holder.tv_pay_type.setText("应收金额："+info.getMoney());
        holder.tv_money.setText("实收金额："+info.getReal_money());
        holder.tv_receiver_outtime.setText("收款时间："+info.getReceive_at());
        holder.tv_status.setText("订单状态："+info.getOstatus());
        return view;
    }

    private class ViewHolder{
        TextView tv_order_number;
        TextView tv_create_time;
        TextView tv_receiver_name;
        TextView tv_receiver_phone;
        TextView tv_receiver_address;
        TextView tv_receiver_cpucbt; //收款方式
        TextView tv_pay_type; // 应收金额
        TextView tv_money;  // 实收金额
        TextView tv_receiver_outtime;//收款时间
        TextView tv_status;
        RelativeLayout rl_paystatus;
    }
}
